﻿using Cart.Bll;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Cart.Api.Controllers
{
    public class GoodsTypeController : ApiController
    {
        GoodsTypeBLL bll = new GoodsTypeBLL();
        // GET: api/Goods
        [HttpGet]
        [Route("api/Goods/BuyTypeGood")]
        public List<UniAppGoodJsonDto> Get()
        {
      
            var data = bll.Query();
          var   list = from a in data select new UniAppGoodJsonDto() { 
                id=a.gtId ,
                 name=a.name,
                  icon=a.icon,
                  sort=a.sort,
                   is_show_backstage= a.is_show_backstage,
                    goods_list= from b in a.Goods select  new UniAppGoodDto() 
                    {
                    content=b.content,
                     id=b.gId,
                      images=b.images,
                       name=b.name,
                        price= b.price,
                        property= from  c in b.GoodsPropertyKey
                                  select new UniAppGoodPropertyKeyDto()
                                  {
                                      id = c.gId,
                                      name = c.GoodsSpecKey.name,
                                      values = from d in c.GoodsPropertyValue
                                               select new UniAppGoodPropertyValueDto()
                                               {
                                                   id = d.gpvId,
                                                   code = d.GoodsSpecValue.code,
                                                   is_default = d.is_default,
                                                   value =d.GoodsSpecValue.value
                                               }
                                  }
                        
                          
                    }
                        };
            return list.ToList();
        }

        // GET: api/Goods/5

        public ResultData<List<GoodTypeDto>> Get(string a="")
        {
            var data = new GoodsTypeBLL().Query();
            ResultData<List<GoodTypeDto>> result = new ResultData<List<GoodTypeDto>>();
            List<GoodTypeDto> list = new List<GoodTypeDto>();
            foreach (var item in data)
            {
                list.Add(new GoodTypeDto()
                {
                    GTID = item.gtId,
                    Name = item.name,
                    Icon = item.icon,
                    Is_Show_Backstage = item.is_show_backstage,
                    Sort = item.sort
                });
            }

            result.code = 1;
            result.msg = "ok";
            result.data = list;

            return result;
        }

        // POST: api/Goods
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/Goods/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/Goods/5
        public void Delete(int id)
        {
        }
    }
}
